package org.example.spring_principle.component;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.example.spring_principle.model.Dog;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BeanLifeComponent implements BeanNameAware {
    private Dog dog;
    public BeanLifeComponent() {
        System.out.println("执行构造函数");
    }
    @Autowired
    public void setDog(Dog dog) {
        this.dog = dog;
        System.out.println("执行set方法，完成属性装配...");
    }
    public void init(){
        System.out.println("执行init方法...");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("执行setBeanName方法...,name:"+name);
    }
    @PostConstruct
    public void use(){
        System.out.println("执行use方法...");
    }
    @PreDestroy
    public void destroy() {
        System.out.println("执行destroy方法...");
    }
}
